<template>
  <el-form label-width="220px" :model="formData">
    <p>基础信息</p>
    <el-form-item label="岗位">
      <el-input v-model="formData.post" class="el_inputW" placeholder="请输入岗位信息" />
    </el-form-item>
    <el-form-item label="转正状态">
      <el-select v-model="formData.stateOfCorrection" disabled class="el_inputW">
        <el-option v-for="item of employee.positiveType" :key="item.id" :label="item.value" :value="item.id" />
      </el-select>
    </el-form-item>
    <el-form-item label="职级">
      <el-input v-model="formData.rank" class="el_inputW" placeholder="请输入职级信息" />
    </el-form-item>
    <el-form-item label="转正评价">
      <el-input v-model="formData.correctionEvaluation" type="textarea" :rows="3" class="el_inputW" placeholder="请输入转正评价" />
    </el-form-item>
    <el-form-item label="汇报对象">
      <el-select v-model="formData.reportId" filterable class="el_inputW">
        <el-option v-for="(item,index) of report" :key="index" :value="item" :label="item" />
      </el-select>
    </el-form-item>
    <el-form-item label="HRBP">
      <el-select v-model="formData.hrbp" filterable class="el_inputW">
        <el-option v-for="(item,index) of hrbp" :key="index" :value="item" :label="item" />
      </el-select>
    </el-form-item>
    <el-form-item label="调整司龄(天)">
      <el-input v-model="formData.adjustmentAgedays" class="el_inputW" placeholder="请输入司龄信息" />
    </el-form-item>
    <el-form-item label="首次参加工作时间">
      <el-date-picker v-model="formData.workingTimeForTheFirstTime" class="el_inputW" placeholder="请选择" />
    </el-form-item>
    <el-form-item label="调整工龄">
      <el-input v-model="formData.adjustmentOfLengthOfService" class="el_inputW" placeholder="请输入工龄信息" disabled />
    </el-form-item>
    <p>合同信息</p>
    <el-form-item label="首次合同开始时间">
      <el-date-picker v-model="formData.initialContractStartTime" placeholder="请选择日期" class="el_inputW" />
    </el-form-item>
    <el-form-item label="首次合同结束时间">
      <el-date-picker v-model="formData.firstContractTerminationTime" placeholder="请选择日期" class="el_inputW" />
    </el-form-item>
    <el-form-item label="现合同开始时间">
      <el-date-picker v-model="formData.currentContractStartTime" placeholder="请选择日期" class="el_inputW" />
    </el-form-item>
    <el-form-item label="现合同结束时间">
      <el-date-picker v-model="formData.closingTimeOfCurrentContract" placeholder="请选择日期" class="el_inputW" />
    </el-form-item>
    <el-form-item label="合同期限">
      <el-select v-model="formData.contractPeriod" class="el_inputW">
        <el-option v-for="item of employee.contractPeriod" :key="item.id" :label="item.value" :value="item.id" />
      </el-select>
    </el-form-item>
    <el-form-item label="续签次数">
      <el-select v-model="formData.renewalNumber" class="el_inputW">
        <el-option v-for="item of employee.renewalCount" :key="item.id" :label="item.value" :value="item.id" />
      </el-select>
    </el-form-item>
    <p>招聘信息</p>
    <el-form-item label="招聘渠道">
      <el-select v-model="formData.recruitmentChannels" class="el_inputW">
        <el-option v-for="item of employee.resumeSource" :key="item.id" :label="item.value" :value="item.id" />
      </el-select>
    </el-form-item>
    <el-form-item label="其他招聘渠道">
      <el-input v-model="formData.otherRecruitmentChannels" class="el_inputW" placeholder="请输入其他招聘渠道" />
    </el-form-item>
    <el-form-item label="社招/校招">
      <el-select v-model="formData.socialRecruitment" class="el_inputW">
        <el-option v-for="item of employee.hireSourceType" :key="item.id" :label="item.value" :value="item.id" />
      </el-select>
    </el-form-item>
    <el-form-item label="推荐企业人">
      <el-input v-model="formData.recommenderBusinessPeople" class="el_inputW" placeholder="请输入推荐企业人" />
    </el-form-item>
    <el-row style="margin-left: 280px">
      <el-button size="small" type="primary" :loading="loading" @click="saveJobInfo">保存更新</el-button>
      <el-button size="small" @click="$router.push({name: 'employees'})">返回</el-button>
    </el-row>
  </el-form>
</template>

<script>
import employee from '@/utils/employees'
import { getAllList } from '@/api/department'
import { getAllDetail, getUserJobInfo, saveUserJobInfo } from '@/api/employee'
export default {
  name: 'JobInfo',
  data() {
    return {
      employee,
      id: this.$route.params.id,
      report: [],
      hrbp: [],
      formData: {
        adjustmentAgedays: '', // 调整司龄天
        adjustmentOfLengthOfService: '', // 调整工龄天
        closingTimeOfCurrentContract: '', // 现合同结束时间
        companyId: '', // 公司ID
        contractDocuments: '', // 合同文件
        contractPeriod: '', // 合同期限
        correctionEvaluation: '', //  转正评价
        currentContractStartTime: '', // 现合同开始时间
        firstContractTerminationTime: '', // 首次合同结束时间
        hrbp: '', // HRBP
        initialContractStartTime: '', // 首次合同开始时间
        otherRecruitmentChannels: '', // 其他招聘渠道
        post: '', // 岗位
        rank: null, // 职级
        recommenderBusinessPeople: '', // 推荐企业人
        recruitmentChannels: '', // 招聘渠道
        renewalNumber: '', // 续签次数
        reportId: '', // 汇报对象
        reportName: null, // 汇报对象
        socialRecruitment: '', // 社招校招
        stateOfCorrection: '', // 转正状态
        taxableCity: '', // 纳税城市
        userId: '', // 员工ID
        workMailbox: '', // 工作邮箱
        workingCity: '', // 工作城市
        workingTimeForTheFirstTime: '' // 首次参加工作时间
      },
      pageInfo: {
        page: 1,
        size: 5,
        total: 0
      },
      loading: false
    }
  },
  created() {
    this.getAllList()
    this.getAllEmployee()
    this.getUserJobInfo()
  },
  methods: {
    // 获取管理员列表
    async getAllList() {
      const { depts } = await getAllList()
      const newArr = depts.filter(item => item.manager).map(value => value.manager)
      this.report = [...new Set(newArr)]
    },
    // 获取hrbp列表，人事部
    async getAllEmployee() {
      const { total } = await getAllDetail(this.pageInfo)
      this.pageInfo.total = total
      const { rows } = await getAllDetail({ page: 1, size: this.pageInfo.total })
      this.hrbp = rows.filter(item => item.departmentName === '人事部').map(value => value.username)
    },
    // 获取员工岗位信息
    async getUserJobInfo() {
      this.formData = await getUserJobInfo(this.id)
    },
    // 保存员工岗位信息
    async saveJobInfo() {
      this.loading = true
      await saveUserJobInfo(this.formData)
      this.loading = false
      this.$message.success('保存用户岗位信息成功')
    }
  }
}
</script>

<style>

</style>
